package com.gmall.product.controller;

import com.gmall.common.result.Result;
import com.gmall.model.product.BaseAttrInfo;
import com.gmall.model.product.BaseAttrValue;
import com.gmall.product.service.BaseAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/baseAttr/")
public class BaseAttrController {

    @Autowired
    BaseAttrService baseAttrService;
    @GetMapping(value = {
            "attrInfoList/{category1Id}",
            "attrInfoList/{category1Id}/{category2Id}",
            "attrInfoList/{category1Id}/{category2Id}/{category3Id}"
    })
    public Result<List<BaseAttrInfo>> attrInfoList(
            @PathVariable Long category1Id,
            @PathVariable(required = false) Long category2Id,
            @PathVariable(required = false) Long category3Id) {
        return baseAttrService.attrInfoList(category1Id,category2Id,category3Id);

    }

    @GetMapping(value = {
            "attrInfoList1/{category1Id}",
            "attrInfoList1/{category1Id}/{category2Id}",
            "attrInfoList1/{category1Id}/{category2Id}/{category3Id}"
    })
    public Result<List<BaseAttrInfo>> attrInfoList1(
            @PathVariable Long category1Id,
            @PathVariable(required = false) Long category2Id,
            @PathVariable(required = false) Long category3Id) {
        return baseAttrService.attrInfoList1(category1Id,category2Id,category3Id);

    }

    @GetMapping(value = {
            "attrInfoList2/{category1Id}",
            "attrInfoList2/{category1Id}/{category2Id}",
            "attrInfoList2/{category1Id}/{category2Id}/{category3Id}"
    })
    public Result<List<BaseAttrInfo>> attrInfoList2(
            @PathVariable Long category1Id,
            @PathVariable(required = false) Long category2Id,
            @PathVariable(required = false) Long category3Id) {
        return baseAttrService.attrInfoList2(category1Id,category2Id,category3Id);

    }

    @PostMapping("saveAttrInfo")
    public Result<String> saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
        return baseAttrService.saveAttrInfo(baseAttrInfo);

    }
    @GetMapping("getAttrValueList/{attrId}")
    public Result<List<BaseAttrValue>> getAttrValueList(@PathVariable Long attrId) {
        return baseAttrService.getAttrValueList(attrId);
    }

    @DeleteMapping("deleteAttrInfo/{attrId}")
    public Result<String> deleteAttrInfo(@PathVariable Long attrId) {
        return baseAttrService.deleteAttrInfo(attrId);
    }
}
